package com.niit.userinterface;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    String[] contacts = {"小张", "小强", "小红", "小天", "小乖", "小罗", "小明"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 1.先找到ListView,通过findViewById() 方法
        ListView listview = findViewById(R.id.lv);
        // 2.创建适配器
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, contacts);
        // 3.给listview设置适配器
        listview.setAdapter(adapter);


    }
}